package cn.cheery.springboot.controller;

import cn.cheery.springboot.entity.UserInfo;
import cn.cheery.springboot.service.impl.UserInfoServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.io.IOException;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author Cheery
 * @since 2021-06-30
 */
@Controller
public class UserInfoController {

    @Autowired
    UserInfoServiceImpl userInfoService;

    @RequestMapping("/login")
    @ResponseBody
    public boolean login(@RequestParam(value = "username") String username, @RequestParam(value = "password") String password) throws IOException {
        UserInfo userInfo = userInfoService.findByUsername(username);
        if(userInfo != null){
            if(password.equals(userInfo.getPassword()))
                return true;
            else
                return false;
        }else{
            return false;
        }
    }

    @RequestMapping("/home")
    public String home(){
        return "home";
    }
}
